<template>
  <el-row justify="space-around" style="overflow-x: scroll">
    <el-col :xs="24" :lg="3">
      <Aside/>
    </el-col>
    <el-col :xs="24" :lg="20">
      <router-view></router-view>
    </el-col>
  </el-row>
</template>

<script>
import Aside from "@/views/profile/user/asideNav";
import {wsURlMulti} from "@/setting";
export default {
  name: "user",
  components: {Aside},
  mounted() {
    this.localSocket()
  },
  unmounted() {
    this.$websocket.wsT.close()
  },
  methods:{
    localSocket() {
      let that = this;
      const userId = this.$store.state.user.userId;
      if ("WebSocket" in window) {
        //建立websocket连接
          // that.ws = new WebSocket(`ws://localhost:8002/ticket/${userId}`);
        if (userId!==''){
          that.ws = new WebSocket(`${wsURlMulti}${userId}`);
          that.$websocket.setWsT(that.ws)
          that.ws.onopen=function (){
            // console.log("已连接2")
        }
        }

        //连接关闭
        that.ws.onclose = function() {
          // 关闭 websocket
          // console.log("连接已关闭");
          setTimeout(() => {
            //断线重连
            that.localSocket();
          }, 4000);
        }
        //连接错误
        that.ws.onerror=function(e){
          console.log("连接错误！")
        }
      } else {
        // 浏览器不支持 WebSocket
        console.log("您的浏览器不支持 WebSocket!");
      }
    },
  }
}
</script>

<style scoped>

</style>
